#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct car{
	int d,v,a;//d:zuo biao,v:chu su du,a:jia su du
}c[maxn];
int p[maxn];
bool use[15];
int n,m,l,V;
int ans,res = -1e9;
void dfs(int pos,int cnt)
{
	if(pos > m)
	{
		int sum = 0;
		for(int i = 1;i <= n;i++)
		{
			int f = 0;
			for(int j = 1;j <= m;j++)
			{
				if(!use[j]) continue;
				if(c[i].d > p[j]) continue;
				double ssv = 1.0 * c[i].v * c[i].v + 1.0 * 2 * c[i].a * (p[j] - c[i].d);  //shun shi su du
				ssv = sqrt(ssv);
				int v1 = ceil(ssv);
				if(v1 > V) f = 1;
			}
			sum += f;
		}
		if(sum != ans) return;
		res = max(res,cnt);
		return;
	}
	use[pos] = 0;
	dfs(pos + 1,cnt + 1);
	use[pos] = 1;
	dfs(pos + 1,cnt);
}
void solve()
{
	cin >> n >> m >> l >> V;
	bool f1 = 1,f2 = 1,f3 = 1;
	for(int i = 1;i <= n;i++)
	{
		int x,y,z;
		cin >> x >> y >> z;
		c[i] = {x,y,z};
		if(z == 0)
		{
			f2 = f3 = 0;
		}
		else if(z > 0) f1 = f3 = 0;
		else f1 = f2 = 0;
	}
	for(int i = 1;i <= m;i++)
	{
		cin >> p[i];
	}
	if(f1) //ai=0:20pts
	{
		int ans = 0;
		int pos = -1e9;
		for(int i = 1;i <= m;i++)
		{
			pos = max(pos,p[i]);
		}
		for(int i = 1;i <= n;i++)
		{
			if(c[i].d > pos) continue;
			if(c[i].v > V) ans++;
		}
		if(!ans) m++;
		cout << ans << ' ' << m - 1 << endl;
		return;
	}
	else if(f2) //ai>0:20pts
	{
		int ans = 0;
		int pos = -1e9;
		for(int i = 1;i <= m;i++)
		{
			pos = max(pos,p[i]);
		}
		for(int i = 1;i <= n;i++)
		{
			if(c[i].d > pos) continue;
			double ssv = 1.0 * c[i].v * c[i].v + 1.0 * 2 * c[i].a * (pos - c[i].d);  //shun shi su du
			ssv = sqrt(ssv);
			int v1 = ceil(ssv);
			if(v1 > V) ans++;
		}
		if(!ans) m++;
		cout << ans << ' ' << m - 1 << endl;
		return;
	}
	if(n <= 20) //n,m<=10:10pts
	{
		memset(use,0,sizeof(use));
		ans = 0;
		res = -1e9;
		for(int i = 1;i <= n;i++)
		{
			int f = 0;
			for(int j = 1;j <= m;j++)
			{
				if(c[i].d > p[j]) continue;
				double ssv = 1.0 * c[i].v * c[i].v + 1.0 * 2 * c[i].a * (p[j] - c[i].d);  //shun shi su du
				ssv = sqrt(ssv);
				int v1 = ceil(ssv);
				if(v1 > V) f = 1;
			}
			ans += f;
		}
		cout << ans << ' ';
		dfs(1,0);
		cout << res << endl;
	}
}
int main()
{
	//all :50pts
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int t;
	cin >> t;
	while(t--) solve();
	return 0;
}
